package com.ityangxu.langchain4j.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ityangxu.langchain4j.entity.Result;
import com.ityangxu.langchain4j.entity.User;
import com.ityangxu.langchain4j.entity.UserDto;
import com.ityangxu.langchain4j.mapper.UserMapper;
import com.ityangxu.langchain4j.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;



@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public Result<IPage<User>> getUserList(UserDto userDto) {
        LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper
                .eq(userDto.getUsername() != null, User::getUsername, userDto.getUsername())
                .eq(userDto.getGender() != null, User::getGender, userDto.getGender())
                .between(userDto.getEnd_time() != null && userDto.getStart_time() != null, User::getCreatedAt, userDto.getStart_time(), userDto.getEnd_time());

        Page<User> page = new Page<>(userDto.getCurrent_page(), userDto.getPage_size());
        IPage<User> userPage = this.page(page, lambdaQueryWrapper);
        return Result.success(userPage);
    }

}
